<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
	<title>人事管理系统——添加员工</title>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
	<meta http-equiv="pragma" content="no-cache"/>
	<meta http-equiv="cache-control" content="no-cache"/>
	<meta http-equiv="expires" content="0"/>
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3"/>
	<meta http-equiv="description" content="This is my page"/>
	<link href="../css/css.css" type="text/css" rel="stylesheet"/>
	<link rel="stylesheet" type="text/css" href="../js/ligerUI/skins/Aqua/css/ligerui-dialog.css"/>
	<link href="../js/ligerUI/skins/ligerui-icons.css" rel="stylesheet" type="text/css"/>
	<script type="text/javascript" src="../js/jquery-1.11.0.js"></script>
	<script type="text/javascript" src="../js/jquery-migrate-1.2.1.js"></script>
	<script src="../js/ligerUI/js/core/base.js" type="text/javascript"></script>
	<script src="../js/ligerUI/js/plugins/ligerDrag.js" type="text/javascript"></script>
	<script src="../js/ligerUI/js/plugins/ligerDialog.js" type="text/javascript"></script>
	<script src="../js/ligerUI/js/plugins/ligerResizable.js" type="text/javascript"></script>
	<link href="../css/pager.css" type="text/css" rel="stylesheet"/>
	<script language="javascript" type="text/javascript" src="../js/My97DatePicker/WdatePicker.js"></script>
</head>
<body>
	<table width="100%" border="0" cellpadding="0" cellspacing="0">
		<tr>
			<td height="10"></td>
		</tr>
		<tr>
			<td width="15" height="32"><img src="../images/main_locleft.gif" width="15" height="32"></td>
			<td class="main_locbg font2"><img src="../images/pointer.gif">&nbsp;&nbsp;&nbsp;当前位置：员工管理 &gt; 添加员工</td>
			<td width="15" height="32"><img src="../images/main_locright.gif" width="15" height="32"></td>
		</tr>
	</table>
	<table width="100%" height="90%" border="0" cellpadding="5" cellspacing="0" class="main_tabbor">
		<tbody>
			<tr valign="top">
				<td>

					<!-- 隐藏表单，flag表示添加标记 -->
					<input type="hidden" name="flag" value="2">
					<table width="100%" border="0" cellpadding="0" cellspacing="10" class="main_tab">
						<tbody>
							<tr>
								<td class="font3 fftd">
									<table>
										<tbody>
											<tr>
												<td class="font3 fftd">姓名：<input type="text" name="name" id="name"
												                                 size="20"></td>
												<td class="font3 fftd">身份证号码：<input type="text" name="cardId"
												                                    id="cardId" size="20"></td>
											</tr>
											<tr>
												<td class="font3 fftd">职&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;位：
													<select name="job_id" style="width:143px;" id="jobId">
													</select>
												</td>
											</tr>
											<tr>
												<td class="font3 fftd">学历：<input name="education" id="education"
												                                 size="20"></td>
												<td class="font3 fftd">邮&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;箱：<input
													name="email" id="email" size="20"></td>
											</tr>
											<tr>
												<td class="font3 fftd">手机：<input name="phone" id="phone" size="20"></td>
												<td class="font3 fftd">电&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;话：<input
													name="tel" id="tel" size="20"></td>
											</tr>

										</tbody>
									</table>
								</td>
							</tr>
							<tr>
								<td class="main_tdbor"></td>
							</tr>

							<tr>
								<td class="font3 fftd">
									政治面貌：<input name="party" id="party" size="40">&nbsp;&nbsp;
									QQ&nbsp;&nbsp;号码：<input name="qqNum" id="qqNum" size="20">
								</td>
							</tr>
							<tr>
								<td class="main_tdbor"></td>
							</tr>

							<tr>
								<td class="font3 fftd">
									联系地址：<input name="address" id="address" size="40">&nbsp;&nbsp;
									邮政编码：<input name="postCode" id="postCode" size="20">
								</td>
							</tr>
							<tr>
								<td class="main_tdbor"></td>
							</tr>

							<tr>
								<td class="font3 fftd">
									出生日期：<input cssclass="Wdate"
									            onfocus="WdatePicker({skin:'whyGreen',dateFmt:'yyyy-MM-dd'});"
									            name="birthday" id="birthday" size="40">&nbsp;&nbsp;
									民&nbsp;&nbsp;&nbsp;&nbsp;族：<input name="race" id="race" size="20">
								</td>
							</tr>
							<tr>
								<td class="main_tdbor"></td>
							</tr>
							<tr>
								<td class="font3 fftd">性&nbsp;&nbsp;&nbsp;&nbsp;别：
									<span>男</span>&nbsp;&nbsp;<input type="radio" name="gender"
									                                 id="gender1"
									                                 value="1"/>
									&nbsp;&nbsp;
									<span>女</span>&nbsp;&nbsp;<input type="radio" name="gender"
									                                 id="gender2"
									                                 value="2"/>
								</td>
							</tr>
							<tr>
								<td class="font3 fftd">
									爱&nbsp;&nbsp;&nbsp;&nbsp;好：<input name="hobby" id="hobby" size="20"
									                                  value="">
								</td>
							</tr>
							<tr>
								<td class="main_tdbor"></td>
							</tr>

							<tr>
								<td class="font3 fftd">
									备&nbsp;&nbsp;&nbsp;&nbsp;注：<input name="remark" id="remark" size="40">
									&nbsp;&nbsp;所属部门：
									<select name="dept_id" style="width:100px;" id="deptId">
									</select>
								</td>
							</tr>
							<tr>
								<td class="font3 fftd">部门经理：
									<span>是</span>&nbsp;&nbsp;<input type="radio" name="major"
									                                 id="major1"
									                                 value="1"/>
									&nbsp;&nbsp;
									<span>否</span>&nbsp;&nbsp;<input type="radio" name="major"
									                                 id="major2"
									                                 value="0"/>
								</td>
							</tr>
							<tr>
								<td class="main_tdbor"></td>
							</tr>

							<tr>
								<td align="left" class="fftd">
									<input type="button" onclick="submit()" value="添加">&nbsp;&nbsp;<input type="reset"
									                                                                      value="取消 "
									                                                                      onclick="reset()">
								</td>
							</tr>
						</tbody>
					</table>

				</td>
			</tr>
		</tbody>
	</table>
	<div style="height:10px;"></div>
	<script type="text/javascript">

		function checkResultAndGetData($result) {
			if ($result.success == false) {
				throw $result;
			}
			return $result.data;
		}


		function reset() {
			window.location.replace('/csi/employee/employee.html');
		}


		$(document).ready(function () {
			getDetpType();
			getJobType();

		});

		function submit() {
			let name = $("#name").val();
			let cardId = $("#cardId").val();
			let deptId = $("#deptId").val();
			let jobId = $("#jobId").val();
			let education = $("#education").val();
			let email = $("#email").val();
			let phone = $("#phone").val();
			let tel = $("#tel").val();
			let party = $("#party").val();
			let qqNum = $("#qqNum").val();
			let address = $("#address").val();
			let postCode = $("#postCode").val();
			let birthday = $("#birthday").val();
			let race = $("#race").val();
			let hobby = $("#hobby").val();
			let empSex = $("input[name='gender']:checked").val();
			let empMajor = $("input[name='major']:checked").val();
			let empInfo = {
				"empName": name,
				"empSex": empSex,
				"empMajor": empMajor,
				"cardId": cardId,
				"deptId": deptId,
				"jobId": jobId,
				"empEmail": email,
				"empPhone": phone,
				"empTel": tel,
				"empEdu": education,
				"empParty": party,
				"qqNum": qqNum,
				"empAddress": address,
				"postCode": postCode,
				"empBirthday": birthday,
				"empRace": race,
				"empHobby": hobby
			};

			let msg = "";
			if ($.trim(name) == "") {
				msg = "姓名不能为空！";
				$("#name").focus();
			} else if ($.trim(cardId) == "") {
				msg = "身份证号码不能为空！";
				$("#cardId").focus();
			} else if (!/^[1-9]\d{16}[0-9A-Za-z]$/.test($.trim(cardId))) {
				msg = "身份证号码格式不正确！";
				$("#cardId").focus();
			} else if ($.trim(education) == "") {
				msg = "学历不能为空！";
				$("#education").focus();
			} else if ($.trim(email) == "") {
				msg = "邮箱不能为空！";
				$("#email").focus();
			} else if (!/^\w+@\w{2,3}\.\w{2,6}$/.test($.trim(email))) {
				msg = "邮箱格式不正确！";
				$("#email").focus();
			} else if ($.trim(phone) == "") {
				msg = "手机号码不能为空！";
				$("#phone").focus();
			} else if (!/^1[3|5|8]\d{9}$/.test($.trim(phone))) {
				msg = "手机号码格式不正确！";
				$("#phone").focus();
			} else if ($.trim(tel) == "") {
				msg = "电话号码不能为空！";
				$("#tel").focus();
			} else if (!/^0\d{2,3}-?\d{7,8}$/.test($.trim(tel))) {
				msg = "电话号码格式不正确！";
				$("#tel").focus();
			} else if ($.trim(party) == "") {
				msg = "政治面貌不能为空！";
				$("#party").focus();
			} else if ($.trim(qqNum) == "") {
				msg = "QQ号码不能为空！";
				$("#qqNum").focus();
			} else if (!/^\d{6,}$/.test($.trim(qqNum))) {
				msg = "QQ号码格式不正确！";
				$("#qqNum").focus();
			} else if ($.trim(address) == "") {
				msg = "地址不能为空！";
				$("#address").focus();
			} else if ($.trim(postCode) == "") {
				msg = "邮政编码不能为空！";
				$("#postCode").focus();
			} else if (!/^[1-9]\d{5}$/.test($.trim(postCode))) {
				msg = "邮政编码格式不正确！";
				$("#postCode").focus();
			} else if ($.trim(birthday) == "") {
				msg = "出生日期不能为空！";
				$("#birthday").focus();
			} else if (!/^\d{4}-\d{2}-\d{2}$/.test($.trim(birthday))) {
				msg = "出生日期格式不正确！";
				$("#birthday").focus();
			} else if ($.trim(race) == "") {
				msg = "民族不能为空！";
				$("#race").focus();
			} else if ($.trim(hobby) == "") {
				msg = "爱好不能为空！";
				$("#hobby").focus();
			}
			if (msg != "") {
				$.ligerDialog.error(msg);
				return false;
			}
			console.log(JSON.stringify(empInfo))
			$.ajax({
				type: "POST",
				url: "/csi/emp/api/insert",
				async: true,
				contentType: 'application/json;charset=UTF-8',
				data: JSON.stringify(empInfo),
				dataType: "json",
				error: function (XMLHttpRequest, textStatus, text) {
					$.ligerDialog.error(JSON.stringify(text), "出错了，请于管理员联系");
				},
				success: function (result) {
					console.log(result);
					let data;
					try {
						data = checkResultAndGetData(result);
					} catch (error) {
						console.log(error)
						// alert(JSON.stringify(error));
						$.ligerDialog.error("出错了，请于管理员联系");
						return;
					}
					if (data) {
						$.ligerDialog.success("添加成功");
					} else {
						$.ligerDialog.warn("添加失败");
					}
				}
			});
		}

		function getJobType() {
			$.ajax({
				url: "/csi/job/api/list",
				type: "GET", // type of action POST || GET
				success: function (result) {
					// console.log(result);
					let data;
					try {
						data = checkResultAndGetData(result);
					} catch (error) {
						console.log(error)
						// alert(JSON.stringify(error));
						$.ligerDialog.error(JSON.stringify(error), "出错了，请于管理员联系");
						return;
					}

					// 渲染页面
					if (data.length > 0) {
						let content = '';
						$('#jobId').empty();
						content = content + '<option value="">-请选择职位-</option>';
						for (let i in data) {
							content = content + '<option value="' + data[i].id + '">' + data[i].jobName + '</option>';
						}
						$('#jobId').append(content);
					} else {
						$('#jobId').empty();
					}
				}
			});
		}

		function getDetpType() {
			$.ajax({
				url: "/csi/dept/api/list",
				type: "GET", // type of action POST || GET
				success: function (result) {
					// console.log(result);
					let data;
					try {
						data = checkResultAndGetData(result);
					} catch (error) {
						console.log(error)
						// alert(JSON.stringify(error));
						$.ligerDialog.error(JSON.stringify(error), "出错了，请于管理员联系");
						return;
					}

					// 渲染页面
					if (data.length > 0) {
						let content = '';
						$('#deptId').empty();
						content = content + '<option value="">-请选择部门-</option>';
						for (let i in data) {
							content = content + '<option value="' + data[i].id + '">' + data[i].deptName + '</option>';
						}
						$('#deptId').append(content);
					} else {
						$('#deptId').empty();
					}
				}
			});
		}
	</script>
</body>
</html>